package com.github.demo.controller;

import com.github.demo.feign.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Created by guxiaowei on 2018/3/1.
 */
@RestController
@RefreshScope
@RequestMapping("/consumer")
public class DemoController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Value("${info}")
    private String info;

    @Autowired
    LoadBalancerClient loadBalancerClient;
    @Autowired
    RestTemplate restTemplate;

    @Autowired
    UserService userService;

    @GetMapping("/ribbon")
    public String consumer(){
        return restTemplate.getForObject("http://cloud-service/user",String.class);
    }

    @GetMapping("/feign")
    public String consumer1(){
        return userService.user();
    }

    @GetMapping("/info")
    public String profile(){
        return info;
    }
}
